<?php
/**
 * Created by JetBrains PhpStorm.
 * User: dung
 * Date: 2/19/14
 * Time: 2:36 AM
 * To change this template use File | Settings | File Templates.
 */
?>
<div id="maincp">
    <h1 class="h1">List Manager</h1>
    <ul class="list">
        <li><a href="index.php?p=addrecruitment" title="Add Recruitment">Add Recruitment</a></li>
    </ul>
    <table class="datatable">
        <thead>
        <tr>
            <td>Title</td>
            <td>Content</td>
            <td>Date Added</td>
            <td>User Posted</td>
        </tr>
        <thead>
        <?php
        if (isset($_GET["page"])) {
            $page  = $_GET["page"];
        }else{
            $page=1;
        }
        $start = ($page-1) * 10;
        $recruitment=RecruitmentList($start);
        if(mysql_num_rows($recruitment)){
            ?>
            <?php
            while($row_recruitment=mysql_fetch_array($recruitment))
            {
                ob_start();
                ?>
                <tbody>
                <tr>
                    <td>{Title}</td>
                    <td>{content}</td>
                    <td>{DatePosted}</td>
                    <td>{UserPosted}</td>
                    <td><a class="text-dung" href="index.php?p=editrecruitment&recruitment_id={recruitment_id}">Edit</a>
                        -
                        <a class="text-dung" href="index.php?p=deleterecruitment&recruitment_id={recruitment_id}">Delete</a>
                    </td>
                </tr>
                </tbody>
                <?php
                $full=explode(" ",$row_recruitment["date_added"]);
                $rawdate=explode("-",$full[0]);
                $newdate = $rawdate[2]."/".$rawdate[1]."/".$rawdate[0];
                $date=$full[1]." ".$newdate;
                $s= ob_get_clean();
                $s=str_replace("{recruitment_id}",$row_recruitment["recruitment_id"],$s);
                $s=str_replace("{Title}",$row_recruitment["title"],$s);
                $s=str_replace("{content}",$row_recruitment["content"],$s);
                $s=str_replace("{DatePosted}",$date,$s);
                $s=str_replace("{UserPosted}",$row_recruitment["user_id"],$s);
                echo $s;
                ?>
            <?php
            }
        }else{
            ?>
            <tbody>
            <tr>
                <td style="text-align: center" class="no-result" colspan="4">
                    <?php echo "No Result!"; ?>
                </td>
            </tr>
            </tbody>
        <?php }
        ?>
    </table>
    <table width="100%">
        <tr>
            <td>
                <?php
                $qr="SELECT COUNT(recruitment_id) from dt_recruitment";
                $result=mysql_query($qr);
                $row_result=mysql_fetch_array($result);
                $records=$row_result[0];
                $total_pages=ceil($records/10);
                if($total_pages>2){
                    echo "Pages ";
                    for ($i=1; $i<=$total_pages; $i++) {
                        echo "<a href='index.php?p=recruitmentlist&page=".$i."'>".$i."</a> ";
                    }
                }?>
            </td>
        </tr>
    </table>
    <a href="index.php?p=cpanel" title="Back to Dashboard">&laquo; Back to Dashboard</a>
</div>